package cn.school.test;

import cn.school.dao.StudentMapper;
import cn.school.entity.Student;
import cn.school.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.cache.impl.PerpetualCache;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Level2Cache {
    public static void main(String[] args) {

        List<Student> s1 = find1(1, 10);
        System.out.println(s1);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
        List<Student> s2 = find1(1, 10);
        System.out.println(s2);
        System.out.println(s1==s2);
        List<Student> s3 = find1(1, 10);
        List<Student> s4 = find1(1, 10);
        List<Student> s5 = find1(1, 10);
        //modify(210L,"陈宇豪","19911117777");
        //System.out.println(">>>>修改之后");
        List<Student> s6 = find1(2, 10);
        List<Student> s7 = find1(3, 10);
    }
    public static List<Student> find1(int pageNo,int pageSize){
        SqlSession s= MybatisUtil.get();
        StudentMapper mapper = s.getMapper(StudentMapper.class);
        List<Student> students = mapper.paging1(pageNo, pageSize);
        MybatisUtil.close(s);
        return students;
    }
    public static void modify(Long stuno,String newName,String phone){
        Student s=new Student();
        s.setStuno(stuno);
        s.setSname(newName);
        s.setTelephone(phone);
        SqlSession session= MybatisUtil.get();
        StudentMapper mapper = session.getMapper(StudentMapper.class);
        int r=mapper.update(s);
        MybatisUtil.close(session);
        System.out.println(r+"被修改了");
    }
}
